<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算器</title>
    <script src="./lib/vue-2.6.12.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="n1">
        <select v-model="opt">
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">*</option>
            <option value="/">/</option>
        </select>
        <input type="text" v-model="n2">
        <button @click="calc">=</button>
        <input type="text" v-model="n3">
    </div>
    
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                n1: 0,
                n2: 0,
                n3: 0,
                opt: '+'
            },
            methods: {
                calc() {
                    // switch (this.opt) {
                    //     case '+':
                    //         this.n3 = Number(this.n1) + Number(this.n2);
                    //         break;
                    //     case '-':
                    //         this.n3 = Number(this.n1) - Number(this.n2);
                    //         break;
                    //     case '*':
                    //         this.n3 = Number(this.n1) * Number(this.n2);
                    //         break;
                    //     case '/':
                    //         this.n3 = Number(this.n1) / Number(this.n2);
                    //         break;                    
                    //     default:
                    //         break;
                    // }
                    let codeStr = 'this.n3 = Number(this.n1) ' + this.opt + ' Number(this.n2);'
                    this.n3 = eval(codeStr);
                }
            }
        })        
    </script>
</body>

</html>